/*
 5000以下的税率0，5000-10000的税率10%，超过10000的部分税率20%
 */
interface Income {
    double getTax();
}

abstract class BaseIncome implements Income {
    public final double income;
    @Override
    public abstract double getTax();

    public BaseIncome(double income) {
        this.income = income;
    }
}

class IncomeUtil {
    public static double totalTax() {
        Income[] incomes = { new SalaryIncome(20000), new RoyaltyIncome(5000) };
        double total = 0;
        for (Income income: incomes) {
            total += income.getTax();
        }
        return total;
    }
}

class SalaryIncome extends BaseIncome implements Income {
    public SalaryIncome(double income) {
        super(income);
    }

    @Override
    public double getTax() {
        double total = 0;
        if (income <= 5000) {
            return 0;
        } else if (income > 5000 && income <= 10000) {
            return income * 0.1;
        } else {
            return (income - 10000) * 0.2 + 10000 * 0.1;
        }
    }
}

class RoyaltyIncome extends BaseIncome implements Income {
    public RoyaltyIncome(double income) {
        super(income);
    }

    @Override
    public double getTax() {
        return income * 0.2;
    }
}